package com.baizhi;

import cn.afterturn.easypoi.excel.ExcelExportUtil;
import cn.afterturn.easypoi.excel.ExcelImportUtil;
import cn.afterturn.easypoi.excel.entity.ExportParams;
import cn.afterturn.easypoi.excel.entity.ImportParams;
import com.baizhi.dao.GuruDao;
import com.baizhi.entity.Guru;
import com.baizhi.service.GuruService;
import org.apache.poi.ss.usermodel.Workbook;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;

import java.io.*;
import java.util.List;

public class ExcelPoi  extends  CmfzApplicationTests{
    @Autowired
    private GuruService guruService;
    @Autowired
    private GuruDao guruDao;


    @Test
    public void test() throws IOException {
        ExportParams exportParams = new ExportParams("上师的所有数据", "guru");

        List<Guru> gurus = guruDao.selectAll();

        Workbook workbooks = ExcelExportUtil.exportExcel(exportParams, Guru.class, gurus);
        workbooks.write( new FileOutputStream("E:\\资料\\项目资料\\后期项目\\5 poi - day4\\Easy.xlsx"));
    }
    @Test
    public void test1() throws Exception {
        //导入参数
        ImportParams params = new ImportParams();
        params.setTitleRows(1);
        params.setHeadRows(1);
        /**
         * 参数1 流或者文件对象
         * 参数2 实体类的类对象
         * 参数3 导入参数对象
         */
        List<Guru> list = ExcelImportUtil.importExcel(new FileInputStream("E:\\资料\\项目资料\\后期项目\\5 poi - day4\\Easy.xlsx"), Guru.class, params);
        for (Guru guru:list){
            System.out.println(guru);
        }


    }
    @Test
    public void test3() throws IOException {
        ExportParams exportParams = new ExportParams("所有的上师数据", "guru");
        List<Guru> gurus = guruDao.selectAll();
        Workbook workbook = ExcelExportUtil.exportExcel(exportParams, Guru.class, gurus);
        workbook.write(new FileOutputStream("E:\\\\资料\\\\项目资料\\\\后期项目\\\\5 poi - day4\\\\Easy1.xlsx"));

    }

}
